package com.sentrix.auto.printercenter.infrastructure.config;

import com.sentrix.auto.printercenter.infrastructure.agentserver.WebSocketHandshakeInterceptor;
import com.sentrix.auto.printercenter.infrastructure.agentserver.WebSocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@EnableWebSocket
@Configuration
public class WebSocketConfig implements WebSocketConfigurer {
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册WebSocket处理器，映射路径为"/ws/print-center"
        // 允许跨域访问，添加握手拦截器
        registry.addHandler(new WebSocketHandler(), "ws/agent")
                .setAllowedOrigins("*")
                .addInterceptors(new WebSocketHandshakeInterceptor());
    }
}
